package sub.helper
{
	import cpnt.iris.Slot;
	import cpnt.iris.SlotEvent;
	
	import mx.controls.Alert;
	import mx.events.CloseEvent;
	import mx.events.FlexEvent;
	
	import orm.iris.vo.TblCharacterVO;
	
	import sub.event.CharacterEvent;
	import sub.view.Character;
	
	public class CharacterHelper
	{
		private var _view:Character;
		
		public function creationCompleteListener(event:FlexEvent):void
		{
			this._view = event.currentTarget as Character;

			_view.label = _tblCharacterVo.prop_class + " - " + _tblCharacterVo.prop_talent;
			
			_view.addEventListener(SlotEvent.SLOT_EVENT_CLICK, slotClickListener);
		}
		
		/**
		 * 截获Slot发出事件
		 * 重新组织后派发Character事件
		 */
		private function slotClickListener(event:SlotEvent):void
		{
			event.stopPropagation();
			
			_view.dispatchEvent(new CharacterEvent(
				CharacterEvent.CHARACTER_EVENT_CLICK, _tblCharacterVo, event.target as Slot));
		}

		public function btnDeleteClick():void
		{
			var a:Alert = Alert.show(
				"Confirm Delete: " + _tblCharacterVo.prop_class + " - " + _tblCharacterVo.prop_talent, "",
				Alert.YES + Alert.NO, null, confirmDelete, null, Alert.NO);
		}
		private function confirmDelete(event:CloseEvent):void
		{
			if(event.detail == Alert.YES)
				_view.dispatchEvent(new CharacterEvent(CharacterEvent.CHARACTER_EVENT_DELETE, _tblCharacterVo));
		}
		// 职业、天赋
		private var _tblCharacterVo:TblCharacterVO;
		
		public function setTblCharacterVo(value:TblCharacterVO):void
		{
			this._tblCharacterVo = value;
		}
		public function getTblCharacterVo():TblCharacterVO
		{
			return this._tblCharacterVo;
		}
	}
}